public class MinMaxGame {

    public static void main(String[] args) {
        int[] nums = {1,3,5,2,4,8,2,2};
        MinMaxGame minMaxGame = new MinMaxGame();
        System.out.println(minMaxGame.minMaxGame(nums));
    }

    public int minMaxGame(int[] nums) {
        if (nums.length == 1) return nums[0];
        while (true) {
            int[] newNums = new int[nums.length / 2];
            int index = 0;
            for (int i = 0; i < nums.length - 1; i += 2) {
                if ((i / 2) % 2 == 0) {
                    newNums[index++] = Math.min(nums[i], nums[i + 1]);
                } else {
                    newNums[index++] = Math.max(nums[i], nums[i + 1]);
                }
            }
            if (newNums.length == 1) return newNums[0];
            nums = newNums;
        }
    }
}
